<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>上传预测图片</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/style/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/style/icon.css">
<script type="text/javascript" src="<%=path %>/script/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=path %>/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path %>/script/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<div class="easyui-tabs" style="width:700px;height:300px; ">
		<div title="上传机经图片" style="padding:10px">
			
			<form id="fm1" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>机经图片文件:</div>
	            <input id="file_name1" class="easyui-filebox" name="pic" data-options="prompt:'请选择文件'" style="width:50%">
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadPicData(1)" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		
		<div title="上传高分必做图片" style="padding:10px">
			
			<form id="fm2" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>高分必做图片文件:</div>
	            <input id="file_name2" class="easyui-filebox" name="pic" data-options="prompt:'请选择文件'" style="width:50%">
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadPicData(2)" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		
		
	</div>
	<div id="picDiv" style="display:none;">
	   <h2>图片预览：</h2>
	    <img />
	</div>
</body>
<script type="text/javascript">
	function uploadPicData(type){
		var fileVal = $("#file_name"+type).textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'jpg' && fileValArr!= 'jpeg' && fileValArr!= 'gif' && fileValArr!= 'png' && fileValArr!= 'bmp' && fileValArr!= 'JPG' ) {  
	    	   $.messager.alert('提示','请上传图片');
	        return false;  
	       }
	       if(fileVal==''){
	    	   $.messager.alert('提示','请添加图片');
	    	   return false;  
	       }
		$('#fm'+type).form('submit', {
			url: '<%=basePath%>pic/upload?picType='+(type-1),
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
	            
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(picurl){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name1').textbox("clear");
				 $("#picDiv").find("img").attr('src',picurl) ;
				 $("#picDiv").css('display','block') ;
			}
		});
	}
	
	$(function(){
		 
		//$.get('<%=basePath%>pic/find').success(function(picurl){
		//	 $("#picDiv").find("img").attr('src',picurl) ;
		//	 $("#picDiv").css('display','block') ;
		//});
		
	});
	
</script>
</html>